<div>
    <?php
    if (isset($_POST['btnGuardar'])) {

        $link = mysql_connect("localhost", "root", "");
        mysql_set_charset('utf8', $link);
        mysql_select_db("sirpof_db1", $link);
        mysql_set_charset('utf8', $link);

        $Ortodoncia1 = $_POST["Ortodoncia1"];
        $Ortodoncia2 = $_POST["Ortodoncia2"];
        $Protesis1 = $_POST["Protesis1"];
        $Protesis2 = $_POST["Protesis2"];
        $farco1 = $_POST["farco1"];
        $farco2 = $_POST["farco2"];
        $labio1 = $_POST["labio1"];
        $labio2 = $_POST["labio2"];
        $et1 = $_POST["et1"];
        $et2 = $_POST["et2"];
        $txtSeñales = $_POST["txtSeñales"];
        $idpaciente = $_POST["idpaciente"];

        $result = "SELECT DISTINCT po.id_registro FROM odontograma o inner join lista l on o.id_diente = l.idlista INNER JOIN paciente_odontograma po on po.id_registro = o.id_registro INNER JOIN paciente p on p.id_paciente = po.id_paciente WHERE o.activo = 1 AND po.id_paciente = " . $idpaciente;
        $resultQuery = mysql_query($result, $link);

        while ($row1 = mysql_fetch_row($resultQuery)) {
            $idregistro = $row1[0];

            $sqlDx = "INSERT INTO diagnostico_odontograma VALUES (NULL,'" . $idregistro . "','" . $Ortodoncia1 . "','" . $Protesis1 . "','" . $farco1 . "','" . $labio1 . "','" . $et1 . "','1','dxMaxSup');";
//            echo $sqlDx;
            mysql_query($sqlDx, $link);

            $sqlDx2 = "INSERT INTO diagnostico_odontograma VALUES (NULL,'" . $idregistro . "','" . $Ortodoncia1 . "','" . $Protesis1 . "','" . $farco1 . "','" . $labio1 . "','" . $et1 . "','1','dxMaxInf');";
            mysql_query($sqlDx2, $link);
            
            header("Location: odontograma.php?idusuario=".$idpaciente);
        }
    }
    ?>
</div>